 #!/usr/bin/perl -w

 use Bio::DB::Fasta;

 my $fastaFile = $ARGV[0];
 my $numsamples = $ARGV[1];;

 #Build database of fasta file, if not already built.
 print "building database\n";
 my $db = Bio::DB::Fasta->new( $fastaFile );

 #Get the sequence ids
 # print "extracting sequence ids\n";
 my @ids = $db->get_all_ids;

 for($i = 0; $i < $numsamples; $i++) {

      #Get a random sequence ID from @ids
      # print "extracting random sequence " . $i . "\n";
      $seqID = $ids[rand @ids];    

      my $sequence = $db->seq($seqID);
      if  (!defined( $sequence )) {
        die "Sequence $seqID not found. \n" 
       }   
      print ">$seqID\n", "$sequence\n";
 }